﻿// Copyright 2010 Maxime Serrano <lastchronicler@gmail.com>
// Copyright 2009, 2010 Matvei Stefarov <me@matvei.org>
using System;

namespace ForgeCraft
{
    public class CmdTime : Command
    {
        public override string name { get { return "time"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "op"; } }
        public override bool consoleUsable { get { return false; } }
        public override Permission defaultRank { get { return Permission.Guest; } }
        public CmdTime() { }

        public override void Use(Player p, string message)
        {
            if (message != null && message.Length > 0)
            {
                long timeCode;
                try
                {
                    timeCode = long.Parse(message);
                }
                catch
                {
                    p.Message(Color.Announcement + "You must enter a valid timecode!");
                    return;
                }
                Server.SendToAll(Color.Sys + p.nick + " set the world's time to " + message);
                p.currentWorld.time = timeCode;
                Server.SendToAll(PacketWriter.MakeTimeUpdate(timeCode));
            }
            else
            {
                p.Message(Color.Announcement + "The current server time is " + p.currentWorld.time);
                p.Message(Color.Announcement + "To change the time, type " + Color.Help + "/time <time>");
                return;
            }
        }
        public override void Help(Player p)
        {
            p.Message(Color.Aqua + "/time " + Color.Help + "- Sets the sun's position (time) to the number you specify.");
        }
    }
}